package com.ehome.poct.base.dao.device.repository;

import cn.hutool.core.util.ObjectUtil;
import com.ehome.poct.base.api.dto.device.DeviceSnoQry;
import com.ehome.poct.base.api.dto.device.TestDeviceParamDTO;
import com.ehome.poct.base.api.feign.device.DeviceBatchClient;
import com.ehome.poct.base.api.feign.device.DeviceBldSnoClient;
import com.ehome.poct.base.api.qry.device.DeviceBatchQry;
import com.ehome.poct.base.api.vo.device.DeviceBatchVO;
import com.ehome.poct.base.api.vo.device.DeviceBldSnoVO;
import com.ehome.poct.base.dao.device.entity.TestBloodDeviceParamNewDO;
import com.ehome.poct.base.dao.device.entity.TestDeviceDO;
import com.ehome.poct.base.device.repository.AbstractDeviceRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

/**
 * 血常规设备
 *
 * @author muqiu
 * @Date 2022-02-24 09:23
 */
@Repository
public class BloodCellDeviceRepositoryImpl implements AbstractDeviceRepository {
    @Autowired
    private DeviceBatchClient deviceBatchClient;
    @Autowired
    private DeviceBldSnoClient deviceBldSnoClient;
    /**
     * 设备类型
     */
    private final static Integer DEVICE_TYPE = 2;
    
    @Override
    public Boolean deviceType(Integer deviceType) {
        return DEVICE_TYPE.equals(deviceType);
    }

    @Override
    public Boolean addDevice(String sno) {
        DeviceSnoQry deviceSnoQry = new DeviceSnoQry();
        deviceSnoQry.setSno(sno);
        DeviceBldSnoVO deviceBldSnoVO = deviceBldSnoClient.queryOne(deviceSnoQry);
        if (ObjectUtil.isEmpty(deviceBldSnoVO) || ObjectUtil.isEmpty(deviceBldSnoVO.getDeviceBatchSno())) {
            return new TestDeviceDO(sno, "4.0", 2, 2, 12L, 12L, null).insert();
        }
        DeviceBatchQry deviceBatchQry = new DeviceBatchQry();
        deviceBatchQry.setBatchSno(deviceBldSnoVO.getDeviceBatchSno());
        DeviceBatchVO deviceBatchVO = deviceBatchClient.queryOne(deviceBatchQry);
        return new TestDeviceDO(sno, deviceBatchVO.getDeviceVersionType(), 2, 2, 12L, 12L, null).insert();
    }
    
    @Override
    public Boolean addDeviceParam(TestDeviceParamDTO testDeviceParamDTO) {
        return new TestBloodDeviceParamNewDO(testDeviceParamDTO.getDeviceParamData(), testDeviceParamDTO.getDeviceSno(), testDeviceParamDTO.getDeviceSha()).insert();
    }
}
